package com.jinglvhuanjing.app.dialog;

import android.content.Context;
import android.view.Gravity;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jinglvhuanjing.app.R;
import com.jinglvhuanjing.app.adapter.SheetAdapter;
import com.jinglvhuanjing.app.bean.SheetBottomBean;
import com.jinglvhuanjing.app.listener.SheetClickEvent;

import java.util.ArrayList;

public class SheetBottomListDialog extends BaseDialog{
    private final RecyclerView mSheetListView;
    private final AppCompatTextView mCancelBtn;
    private final SheetAdapter mSheetAdapter;

    public SheetBottomListDialog(@NonNull Context context) {
        super(context);
        super.setGravity(Gravity.BOTTOM);
        super.setFullScreenWidth(true);
        setContentView(R.layout.dialog_sheet_bottom_list_layout);
        this.mSheetListView = findViewById(R.id.sheet_list);
        this.mCancelBtn = findViewById(R.id.sheet_cancel_btn);
        this.mSheetAdapter = new SheetAdapter();
        this.mSheetListView.setLayoutManager(new LinearLayoutManager(context));
        this.mSheetListView.setAdapter(this.mSheetAdapter);
        this.mCancelBtn.setOnClickListener(v->dismiss());
//        this.testData();
    }

    public void setSheetClickEvent(SheetClickEvent sheetClickEvent){
        this.mSheetAdapter.setButtonClickEvent(sheetClickEvent);
    }

    public void setData(ArrayList<SheetBottomBean> items){
        this.mSheetAdapter.replaceData(items);
    }

    private void testData(){
        ArrayList<SheetBottomBean> items = new ArrayList<>();
        SheetBottomBean bean;
        for (int i = 0; i < 5; i++) {
            bean = new SheetBottomBean();
            bean.setByteStr("0"+i);
            bean.setLabel(""+i);
            items.add(bean);
        }
        this.mSheetAdapter.replaceData(items);
    }

}
